<extend name="Public/publicHTML" />

<block name='content'>
<link href="__COMMON__/daterangepicker/daterangepicker-bs3.css"
    rel="stylesheet" type="text/css" />
<script src="__COMMON__/daterangepicker/moment.min.js"
    type="text/javascript"></script> <script
    src="__COMMON__/daterangepicker/daterangepicker.js"
    type="text/javascript"></script>
<link rel="stylesheet" href="__COMMON__/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet"
    href="__COMMON__/bootstrap/css/font-awesome.min.css" />

<div class="wrapper">
<section class="content ">
    <!-- Main content -->
    <div class="container-fluid">
        <div class="pull-right">
            <a href="javascript:history.go(-1)" data-toggle="tooltip" title=""
                class="btn btn-default" data-original-title="返回"><i
                class="fa fa-reply"></i></a> 
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <i class="fa fa-list"></i> 编辑积分商品信息
                </h3>
            </div>
            <div class="panel-body ">
                <!--表单数据-->
                <form method="post" id="promotion">
                    <!--通用信息-->
                    <div class="tab-content col-md-10">
                        <div class="tab-pane active" id="tab_tongyong">
                            <table class="table table-bordered">
                                <tbody>
                                    <tr>
                                        <td>选择商品:</td>
                                        <td>
                                        <a class="btn btn-primary" href="javascript:void(0);" onclick="Tool.selectGoods('{:U('searchGoods')}')"><i class="fa fa-search"></i>添加商品</a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <div class="form-group">
                                                <table class="table table-bordered">
                                                    <thead>
                                                        <tr>
                                                            <th style="display: none">选择</th>
                                                            <th class="text-left">商品名称</th>
                                                            <th class="text-left">价格</th>
                                                            <th class="text-left">库存</th>
                                                            <th class="text-left">操作</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody id="goods_list">
                                                    <if condition="!empty($info)">
                                                        <tr>
                                                            <td style="display: none">
                                                            <input type="hidden" name="goods_id" checked="checked" value="{$info['goods_id']}" />
                                                            </td>
                                                            <td class="text-left">{$info.title}</td>
                                                            <td class="text-left">{$info.price_member}</td>
                                                            <td class="text-left">{$info.stock}</td>
                                                            <td class="text-left"><a href="javascript:void(0)"
                                                                onclick="javascript:$(this).parent().parent().remove();">删除</a></td>
                                                        </tr>
                                                    </if>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="col-sm-2">积分限制：</td>
                                        <td class="col-xs-8">
                                            <input type="text" class="form-control w300" id="delayed" name="delayed" value="{$info.delayed}">天<small>用户得到积分后多少天才能兑换这件商品.默认0,最大999</small>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="col-sm-2">需要积分：</td>
                                        <td class="col-xs-8">
                                            <input type="text" class="form-control w300" id="integral" name="integral" value="{$info.integral}">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="col-sm-2">所需支付：</td>
                                        <td class="col-xs-8">
                                            <input type="text" class="form-control w300" id="money" name="money" value="{$info.money}"><small>用户除积分外,还需要支付的金额,为0,则不需要</small>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>兑换状态：</td>
                                        <td><input type="radio" name="status" value="1" <if condition="$info.status eq 1">checked</if> /> 可兑换
                                        <input type="radio" name="status" value="0" <if condition="$info.status eq 0">checked</if> /> 不可兑换
                                        </td>
                                    </tr>
                                    <tr style="display: none;">
                                        <td></td>
                                        <td><input id="integral_id" type="hidden" name="id" value="{$info['id']}" />
                                        </td>
                                    </tr>
                                    
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <td><input class="btn btn-default" type="reset"
                                            value="重置"/>
                                            <input type="hidden" name="" value="">
                                        </td>
                                        <td class="text-right">
                                        <input class="btn btn-primary" type="button" onclick="add(this)" value="保存"></td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                </form>
                <!--表单数据-->
            </div>
        </div>
    </div>
</section>
</div>
<script type="text/javascript" src="__COMMON__/js/jquery-form.js"></script> 
<script type="text/javascript" src="__COMMON__/js/alert.js?a={:time()}"></script> 

<script type="text/javascript">

function callBack(tableHtml)
{
    layer.closeAll('iframe');
    $('#goods_list').html(tableHtml);
}

function add(obj)
{
    var goods_id = $('#goods_list tr td').eq(0).find('input').val();
    console.log(goods_id);
    var id       = $('#integral_id').val();
    var integral = $('#integral').val();
    var money = $('#money').val();
    var delayed  = $('#delayed').val();
    var status   = $('input:radio[name="status"]:checked').val();
    var url      = "{:U('goodsHandle')}";
    var act      = '{$act}';

    if (typeof(goods_id) == 'undefined' || integral < 1) {
        layer.msg('数据请补充完整!');
        return false;
    }
    if (delayed < 0 || delayed>999) {
         layer.msg('积分限制为0~999天!');
        return false;   
    }

    var data = {
        'goods_id':goods_id,
        'integral':integral,
        'money':money,
        'delayed':delayed,
        'status':status,
        'act':act
    }

    if (act == 'edit') {
        data['id'] = id;
    }

    StandardPost(url, data);
}

function StandardPost(url,args) 
{
    var form = $("<form method='post'></form>");
    form.attr({"action":url});
    for (arg in args)
    {
        var input = $("<input type='hidden'>");
        input.attr({"name":arg});
        input.val(args[arg]);
        form.append(input);
    }
    $(document.body).append(form);
    form.submit();
}

</script>
</block>